<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
     <meta name='viewport' content='width=device-width, initial-scale=1.0'>
     <title>日期函数以及时钟案例</title>
     <link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/styles/default.min.css'>
     <script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.6.0/highlight.min.js'></script>
</head>
<body>
    <p class="show-time">当前时间</p>
     <pre>
        <code style='max-height: 400px;'>
            let time = new Date() 
            console.log(time);  // Thu Sep 14 2023 09:36:55 GMT+0800 (中国标准时间)
            console.log(typeof time); // "object"

            // new Date 对象里面的一些属性 方法

            let date = new Date()
            console.log('获取年份',date.getFullYear());
            console.log('获取月份',date.getMonth() + 1);
            // 0-6 周日到周六 周日是0 周六是6
            console.log('今天周几',date.getDay()); 
            console.log('获取几号',date.getDate());

            // 获取时间戳
            console.log('时间戳',date.getTime());
            console.log('获得年月日(包含时分秒) 完整的字符串',date.toLocaleString()); 
            console.log('获取年月日',date.toLocaleDateString());
            let showTime = document.querySelector('.show-time')
            function setTime(){
                let date = new Date()
                let showText = date.toLocaleString()
                showTime.innerText = '当前时间:' + showText
            }
            setTime()
            setInterval(() => {
                setTime()
            },1000)
        </code>
     </pre>
     <script> hljs.highlightAll(); </script>
     <script>
        let time = new Date() 
        console.log(time);  // Thu Sep 14 2023 09:36:55 GMT+0800 (中国标准时间)
        console.log(typeof time); // "object"

        // new Date 对象里面的一些属性 方法

        let date = new Date()
        console.log('获取年份',date.getFullYear());
        console.log('获取月份',date.getMonth() + 1);
        // 0-6 周日到周六 周日是0 周六是6
        console.log('今天周几',date.getDay()); 
        console.log('获取几号',date.getDate());

        // 获取时间戳
        console.log('时间戳',date.getTime());
        console.log('获得年月日(包含时分秒) 完整的字符串',date.toLocaleString()); 
        console.log('获取年月日',date.toLocaleDateString());
        let showTime = document.querySelector('.show-time')
        function setTime(){
            let date = new Date()
            let showText = date.toLocaleString()
            showTime.innerText = '当前时间:' + showText
        }
        setTime()
        setInterval(() => {
            setTime()
        },1000)
     </script>
</body>
</html>